package com.qf.Controller;



import com.qf.Entity.User;
import com.qf.Service.Impl.UserServiceImpl;
import com.qf.Service.UserService;
import com.qf.Util.Constants;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/*2021/10/9*/
@WebServlet( "/user")
public class UserController extends BaseController {
    public String login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            //1.从页面收取参数
        String uAccount = request.getParameter("uAccount");
        String uPassword = request.getParameter("uPassword");
        //2.调用业务
        UserService userService=new UserServiceImpl();
        User user = userService.loginUser(uAccount, uPassword);
        //3.根据结果进行跳转
        if(user!=null){
            request.getSession().setAttribute("user", user);
            return Constants.REDIRECT+"/product?method=selectPage";
        }
        return Constants.REDIRECT+"/login.jsp";
    }

    public String updatePassword(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.收参
        String rePassword = request.getParameter("rePassword");
        String uAccount = request.getParameter("uAccount");
        //2.调用业务
        UserService userService=new UserServiceImpl();
        Integer integer = userService.updatePassword(uAccount, rePassword);
        if(integer>0){
            return Constants.REDIRECT+"/login.jsp";
        }
        return Constants.REDIRECT+"/password.jsp";
    }
}
